<?php
/**
 * @package		简易CMS
 * @subpackage	后台登录模块
 * @version		$Id: admincp_login.php 8 2012-06-07 12:37:35Z htmambo@gmail.com $
 * @author		Hoping
 * @copyright	Copyright (C) 2010 Hoping Software Studio.
 */


if(!defined('IN_JYCMS') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

if($this->core->var['inajax']) {
	ajaxshowheader();
	ajaxshowfooter();
}

if($this->cpaccess == -3) {
	html_login_header(false);
} else {
	html_login_header();
}


if($this->cpaccess == -3) {
	echo  '<p class="logintips">'.lang('admincp_login', 'login_cp_noaccess').'</p>';


}elseif($this->cpaccess == -1) {
	$ltime = $this->sessionlife - (TIMESTAMP - $this->adminsession['dateline']);
	echo  '<p class="logintips">'.lang('admincp_login', 'login_cplock', array('ltime' => $ltime)).'</p>';

}elseif($this->cpaccess == -4) {
	$ltime = $this->sessionlife - (TIMESTAMP - $this->adminsession['dateline']);
	echo  '<p class="logintips">'.lang('admincp_login', 'login_user_lock').'</p>';

} else {
	html_login_form();
}

exit;

function html_login_header($form = true) {
	$charset = CHARSET;
	$title = lang('admincp_login', 'login_title');
	$tips = lang('admincp_login', 'login_tips');
	echo <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>$title</title>
<meta http-equiv="Content-Type" content="text/html;charset=$charset" />
<link rel="stylesheet" href="static/image/admincp/admincp.css" type="text/css" media="all" />
</head>
<body>
EOT;

	if($form) {
		echo <<<EOT
<script language="JavaScript">
	if(self.parent.frames.length != 0) {
		self.parent.location=document.location;
	}
</script>
<table class="logintb">
<tr>
	<td class="login">
		<h1>Control Panel</h1>
		<p>$tips</p>
	</td>

	<td>
EOT;
	}
}

function html_login_form() {
	global $_G;
	$isguest = !getglobal('uid');
	$lang = lang('admincp_login');
	$loginuser = $isguest ? '<input name="admin_username" tabindex="1" type="text" class="txt" autocomplete="off" />' : getglobal('member/username');
	$sid = getglobal('sid');
	$extra = ADMINSCRIPT.'?'.(getgpc('action') && getgpc('frames') ? 'frames=yes&' : '').$_SERVER['QUERY_STRING'];
	$forcesecques = '<option value="0">'.($_G['config']['admincp']['forcesecques'] ? lang('admincp', 'forcesecques') : lang('admincp', 'Security question')).'</option>';
	echo '
		<form method="post" autocomplete="off" name="login" id="loginform" action="'.$extra.'">
		<input type="hidden" name="sid" value="'.$sid.'">
		<input type="hidden" name="frames" value="yes">
		<p class="logintitle">'.lang('admincp', 'Username').': </p>
		<p class="loginform">'.$loginuser.'</p>
		<p class="logintitle">'.lang('admincp', 'Password').':</p>
		<p class="loginform"><input name="admin_password" tabindex="1" type="password" class="txt" autocomplete="off" /></p>
		<p class="logintitle">'.lang('admincp', 'Security question').':</p>
		<p class="loginform">
			<select id="questionid" name="admin_questionid" tabindex="2">
				'.$forcesecques.'
				<option value="1">'.lang('admincp', 'security_question_1').'</option>
				<option value="2">'.lang('admincp', 'security_question_2').'</option>
				<option value="3">'.lang('admincp', 'security_question_3').'</option>
				<option value="4">'.lang('admincp', 'security_question_4').'</option>
				<option value="5">'.lang('admincp', 'security_question_5').'</option>
				<option value="6">'.lang('admincp', 'security_question_6').'</option>
				<option value="7">'.lang('admincp', 'security_question_7').'</option>
			</select>
		</p>
		<p class="logintitle">'.lang('admincp', 'Security answer').':</p>
		<p class="loginform"><input name="admin_answer" tabindex="3" type="text" class="txt" autocomplete="off" /></p>
		<p class="loginnofloat"><input name="submit" value="'.lang('admincp', 'submit').'"  tabindex="3" type="submit" class="btn" /></p>
		</form>';
		echo '<script type="text/JavaScript">document.getElementById(\'loginform\').admin_'.($isguest ? 'username' : 'password').'.focus();</script>';
}
